package net.fdukedom.epicurus.service.interaction;

import java.io.IOException;
import java.io.StringReader;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
 * @author Alexander Kirakozov
 */
public class IdentificationRequestReader extends IdentificationRequest {
	/**
	 * XML request string
	 */
	private String xmlRequest;
	
	/**
	 * Constructor
	 */
	public IdentificationRequestReader(String request) {
		xmlRequest = request;
		createDocument();
	}
	
	@Override
	protected void createDocument() {
		try {
			SAXBuilder builder = new SAXBuilder();
			
			doc = builder.build(new StringReader(xmlRequest));
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	
    /**
     * Returns user email
     * 
     * @return user email
     */
    public String getEmail() {
        return getElementValueByXPath(REQUEST_PREFIX + EMAIL);
    }
    
    /**
     * Returns user password
     * 
     * @return user password
     */
    public String getPassword() {
        return getElementValueByXPath(REQUEST_PREFIX + PASSWORD);
    }
    
	/**
	 * Returns request parameters
	 * 
	 * @return request parameters
	 */
	public Element getParameters() {
		return getElementByXPath(REQUEST_PREFIX + PARAMETERS);
	}
	
	/**
	 * Returns content of parameters element	
	 * @return content of parameters element
	 */
	public String getTextParameter(){
		return getElementValueByXPath(REQUEST_PREFIX + PARAMETERS);
	}
}
